package com.viphuli.app.tool.fragment;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.BaseAdapter;
import android.widget.ListView;
import butterknife.Bind;

import com.loopj.android.http.RequestParams;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.bean.part.ArrangeType;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.common.MyPageHelper;
import com.viphuli.app.tool.handler.MyBaseHttpResponseHandler.HandlerType;
import com.viphuli.app.tool.http.ApiRequest;

/**
 * 排班类型信息
 * 
 * @author li.li
 *
 */
public class ArrangeTypeListFragment extends BaseProgressFragment {

	@Bind(R.id.id_listview)
	protected ListView listview;

	private BaseAdapter adapter;

	List<ArrangeType> list = new ArrayList<ArrangeType>();

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_arrange_type_list;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {

	}
	
	@Override
	public void onStart() {
		super.onStart();
		
		initRequest(HandlerType.loading);
		
	}
	
	@Override
	protected void initRequest(HandlerType handlerType) {
		super.initRequest(handlerType);
		
		AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(getActivity());

		if (tokenKeeper.isLogin()) {

			RequestParams params = new RequestParams();
			params.put("circle_id", tokenKeeper.getUser().circleId());

			ApiRequest.arrangeTypeList.request(this, params);

		}
	}

	@Override
	protected void initData() {

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getActivity().getMenuInflater().inflate(R.menu.menu_arrange_type_edit, menu);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case R.id.id_menu_arrange_type_edit:

			ArrangeTypeEditFragment.go(getActivity());
			return true;

		default:
			break;
		}

		return false;

	}

	public ListView getListview() {
		return listview;
	}

	public List<ArrangeType> getList() {
		return list;
	}

	public void setAdapter(BaseAdapter adapter) {
		this.adapter = adapter;
	}

	public static void go(Activity act) {
		MyPageHelper.arrangeTypeList.showMyPage(act);
	}

}
